package training;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class Training01 {
    public static void main(String[] args) {
//        给定一个字符串：
//        "http://localhost:8080/path?id=1&name=abc&age=30"，
//        请将其中id=1&name=abc&age=30截取出来，并按照键值对的方式将数据保存到Properties文件中。
        String url = "http://localhost:8080/path?id=1&name=abc&age=30";
        String str = url.substring(url.indexOf("?") + 1);
        String [] strs = str.split("&");
        Properties properties = new Properties();
        for(String s : strs){
            String [] temp = s.split("=");
            properties.setProperty(temp[0],temp[1]);
        }
        try {
            properties.store(new FileOutputStream("training01.properties"),null);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
